package com.css.fxfzypg.modules.resultManagement.reportManagement.handle;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.annotation.AddData;
import com.css.fxfzypg.base.annotation.CompareAndSwap;
import com.css.fxfzypg.base.annotation.Transform;
import com.css.fxfzypg.base.annotation.TransformV2;
import com.css.fxfzypg.manage.sampling.repository.entity.SamplingEntity;
import com.css.fxfzypg.modules.baseData.entity.HosPeoEntity;
import com.css.fxfzypg.modules.baseData.entity.VillageTownHosPeoEntity;
import com.css.fxfzypg.modules.resultManagement.reportManagement.entity.KeyDisaterStatics;
import com.css.fxfzypg.modules.resultManagement.reportManagement.repository.ReportManagementRepository;
import com.css.fxfzypg.modules.resultManagement.reportManagement.ypg.HosPeo;
import com.css.fxfzypg.modules.resultManagement.reportManagement.ypg.SeismicCapacityAnalysisForTable;
import com.css.fxfzypg.modules.resultManagement.reportManagement.ypg.StructureType;
import com.css.fxfzypg.modules.resultManagement.reportManagement.ypg.Suggestion;
import com.css.fxfzypg.modules.resultupload.repository.entity.PrefectureResultEntity;
import com.css.fxfzypg.modules.resultupload.repository.entity.ResultEntity;
import com.css.fxfzypg.modules.resultupload.repository.entity.ResultMainEntity;
import com.css.fxfzypg.modules.resultupload.vo.ResultMainEntityVO;
import com.css.fxfzypg.modules.test.CustomXWPFDocument;
import com.css.fxfzypg.util.PlatformObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Dbj
 * @date 2023年04月28日  12:36
 * 用于报告的handle
 */
@Component
public class ReportHandle {

    @Resource
    private ReportManagementRepository reportManagementRepository;


    public  void uploadFile(String fileName, String savePath, MultipartFile multipartFile) throws IOException {
        // 获取文件的后缀名
        assert fileName != null;
        //判断文件夹是否存在如果不存在则创建
        if (!new File(savePath).exists()) {
            new File(savePath).mkdirs();
        }
        File file = new File(savePath, fileName);
        multipartFile.transferTo(file);
    }

    public  JSONObject getSubArea(String taskId){
        JSONObject jsonObject = new JSONObject();
        List<Map<String,Object>> objects=reportManagementRepository.getSubArea(taskId);
        if(PlatformObjectUtils.isEmpty(objects)){
            return null;
        }
        AtomicInteger provinceNum = new AtomicInteger(0);
        AtomicInteger cityNum = new AtomicInteger(0);
        AtomicInteger areaNum = new AtomicInteger(objects.size());
        Map<String,Map<String,List<String>>> mapMap = new HashMap<>();
        for (Map map : objects){
            String province = String.valueOf(map.get("province"));
            String city = String.valueOf(map.get("city"));
            String area = String.valueOf(map.get("area"));

            Map<String,List<String>> listMap;
            List<String> list;
            if (mapMap.containsKey(province)){
                listMap = mapMap.get(province);
                if (listMap.containsKey(city)){
                    list=listMap.get(city);
                }else {
                    list=new ArrayList<>();
                    cityNum.getAndIncrement();
                }
            }else {
                listMap=new HashMap<>();
                list=new ArrayList<>();
                provinceNum.getAndIncrement();
                cityNum.getAndIncrement();
            }
            list.add(area);
            listMap.put(city,list);
            mapMap.put(province,listMap);
        }
        jsonObject.put("mapMap",mapMap);
        jsonObject.put("num", provinceNum.get()+"_"+cityNum.get()+"_"+areaNum.get());
        return jsonObject;
    }

    public String getStructureName(Integer structureNum){
        String structureName = "";
        switch (structureNum) {
            case 0:
                structureName ="高层结构";
                return structureName;
            case 1:
                structureName ="钢结构";
                return structureName;
            case 2:
                structureName ="混凝土结构";
                return structureName;
            case 3:
                structureName ="砖混结构";
                return structureName;
            case 4:
                structureName ="砖木结构";
                return structureName;
            case 5:
                structureName ="土结构";
                return structureName;
            case 6:
                structureName ="木结构";
                return structureName;
            case 7:
                structureName ="石结构";
                return structureName;
            case 8:
                structureName ="其他结构";
                return structureName;
            default:
                structureName = "高层结构";
                return structureName;
        }
    }

    /**
     *  根据结构类型获取典型结构特征
     */
    public String getFurure(SamplingEntity entity,String buildingStructure) {
        String structureName = "";
        switch (Integer.parseInt(buildingStructure)) {
            case 0:
                structureName ="高层结构";
                return entity.getHighFeature();
            case 1:
                structureName ="钢结构";
                return entity.getSteelFeature();
            case 2:
                structureName ="混凝土结构";
                return entity.getConcreteFeature();
            case 3:
                structureName ="砖混结构";
                return entity.getMasonryFeature();
            case 4:
                structureName ="砖木结构";
                return entity.getBrickWoodFeature();
            case 5:
                structureName ="土结构";
                return entity.getSoilFeature();
            case 6:
                structureName ="木结构";
                return entity.getWoodFeature();
            case 7:
                structureName ="石结构";
                return entity.getStoneFeature();
            case 8:
                structureName ="其他结构";
                return entity.getOtherFeature();
            default:
                structureName = "高层结构";
                return entity.getHighFeature();
        }
    }

    /**
     *  将实体中标有指定注解的属性封装在字符串类型的List集合中用于表格行中各个列的数据渲染
     */
    public List<String> getEntityStringList(Object obj) {
        List<String> list = new ArrayList<>();
        KeyDisaterStatics keyDisaterStatics = null;
        Suggestion suggestion = null;
        StructureType structureType = null;
        SeismicCapacityAnalysisForTable table = null;
        HosPeo hosPeo = null;
        Field[] fields = null;
        if (obj instanceof KeyDisaterStatics) {
            keyDisaterStatics = (KeyDisaterStatics) obj;
            fields = keyDisaterStatics.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Object valueObj = getFieldValue(keyDisaterStatics, name);
                list.add(null==valueObj ? "" : valueObj.toString());
            }
        }else if(obj instanceof Suggestion){
            suggestion = (Suggestion) obj;
            fields = suggestion.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Object valueObj = getFieldValue(suggestion, name);
                list.add(null==valueObj ? "" : valueObj.toString());
            }
        } else if(obj instanceof StructureType){
            structureType = (StructureType) obj;
            fields = structureType.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Object valueObj = getFieldValue(structureType, name);
                list.add(null==valueObj ? "" : valueObj.toString());
            }
        }else if(obj instanceof SeismicCapacityAnalysisForTable){
            table = (SeismicCapacityAnalysisForTable) obj;
            fields = table.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Object valueObj = getFieldValue(table, name);
                list.add(null==valueObj ? "" : valueObj.toString());
            }
        }else if(obj instanceof HosPeo){
            hosPeo = (HosPeo) obj;
            fields = hosPeo.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Object valueObj = getFieldValue(hosPeo, name);
                list.add(null==valueObj ? "" : valueObj.toString());
            }
        }
        return list;
    }
    public List<Map<String, Object>> returnTownStructureList(VillageTownHosPeoEntity hosPeo) {
        List<Map<String,Object>> townStructureList = new ArrayList<>(9);
        Map<String,Object> townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "高层建筑");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownHighTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "钢结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownSteelTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "多层钢筋混凝土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownBetonTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖混结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownBrickTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownMasonryTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownSoilTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownWoodTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "石结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownStoneTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "其他结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownOtherTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        return townStructureList;
    }
    public List<Map<String,Object>> returnAreaTownStructureList(HosPeoEntity hosPeo){
        List<Map<String,Object>> townStructureList = new ArrayList<>(9);
        Map<String,Object> townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "高层建筑");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownHighTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "钢结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownSteelTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "多层钢筋混凝土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownBetonTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖混结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownBrickTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownMasonryTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownSoilTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownWoodTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "石结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownStoneTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "其他结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpTownOtherTatio().intValue())+"%");
        townStructureList.add(townStructureMap);
        return townStructureList;
    }
    public List<Map<String, Object>> returnAreaVillageStructureList(HosPeoEntity hosPeo) {
        List<Map<String,Object>> villageStructureList = new ArrayList<>(9);
        Map<String,Object> townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "高层建筑");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageHighTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "钢结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageSteelTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "多层钢筋混凝土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageBetonTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖混结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageBrickTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageMasonryTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageSoilTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageWoodTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "石结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageStoneTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "其他结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageOtherTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        return villageStructureList;
    }

    public List<Map<String, Object>> returnVillageStructureList(VillageTownHosPeoEntity hosPeo) {
        List<Map<String,Object>> villageStructureList = new ArrayList<>(9);
        Map<String,Object> townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "高层建筑");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageHighTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "钢结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageSteelTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "多层钢筋混凝土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageBetonTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖混结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageBrickTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "砖木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageMasonryTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "土结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageSoilTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "木结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageWoodTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "石结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageStoneTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        townStructureMap = new HashMap<>();
        townStructureMap.put("structureTypeName", "其他结构");
        townStructureMap.put("ratio", String.valueOf(hosPeo.getDhpVillageOtherTatio().intValue())+"%");
        villageStructureList.add(townStructureMap);
        return villageStructureList;
    }

    public Map<String, Double> buildSortYearMap(SamplingEntity samplingEntity) {
        Map<String,Double> map = new HashMap<>(9);
        if(Double.valueOf(samplingEntity.getBuild70sBefore())>0.0){
            map.put("70年代前",Double.valueOf(samplingEntity.getHighStructure()));
        }
        if(Double.valueOf(samplingEntity.getBuild70s())>0.0){
            map.put("70年代",Double.valueOf(samplingEntity.getSteelStructure()));
        }
        if(Double.valueOf(samplingEntity.getBuild80s())>0.0){
            map.put("80年代",Double.valueOf(samplingEntity.getConcreteStructure()));
        }
        if(Double.valueOf(samplingEntity.getBuild90s())>0.0){
            map.put("90年代",Double.valueOf(samplingEntity.getMasonryStructure()));
        }
        if(Double.valueOf(samplingEntity.getBuild00s())>0.0){
            map.put("00年代",Double.valueOf(samplingEntity.getBrickWoodStructure()));
        }
        if(Double.valueOf(samplingEntity.getBuild10s())>0.0){
            map.put("10年代",Double.valueOf(samplingEntity.getSoilStructure()));
        }
        if(Double.valueOf(samplingEntity.getBuild20s())>0.0){
            map.put("20年代",Double.valueOf(samplingEntity.getWoodStructure()));
        }
        List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(map.entrySet());
//        Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
//
//            @Override
//            public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
//                return (int) (o2.getValue() - o1.getValue());
//            }
//        });
        Map result = new LinkedHashMap();
        for (Map.Entry<String, Double> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }
        return result;
    }
    public Map<String,Double> buildSortMap(SamplingEntity samplingEntity) {
        Map<String,Double> map = new HashMap<>(9);
        if(Double.valueOf(samplingEntity.getHighStructure())>0.0){
            map.put("高层结构",Double.valueOf(samplingEntity.getHighStructure()));
        }
        if(Double.valueOf(samplingEntity.getSteelStructure())>0.0){
            map.put("钢结构",Double.valueOf(samplingEntity.getSteelStructure()));
        }
        if(Double.valueOf(samplingEntity.getConcreteStructure())>0.0){
            map.put("多层钢筋混凝土结构",Double.valueOf(samplingEntity.getConcreteStructure()));
        }
        if(Double.valueOf(samplingEntity.getMasonryStructure())>0.0){
            map.put("砖混结构",Double.valueOf(samplingEntity.getMasonryStructure()));
        }
        if(Double.valueOf(samplingEntity.getBrickWoodStructure())>0.0){
            map.put("砖木结构",Double.valueOf(samplingEntity.getBrickWoodStructure()));
        }
        if(Double.valueOf(samplingEntity.getSoilStructure())>0.0){
            map.put("土结构",Double.valueOf(samplingEntity.getSoilStructure()));
        }
        if(Double.valueOf(samplingEntity.getWoodStructure())>0.0){
            map.put("木结构",Double.valueOf(samplingEntity.getWoodStructure()));
        }
        if(Double.valueOf(samplingEntity.getStoneStructure())>0.0){
            map.put("石层结构",Double.valueOf(samplingEntity.getStoneStructure()));
        }
        if(Double.valueOf(samplingEntity.getOtherStructure())>0.0){
            map.put("其他结构",Double.valueOf(samplingEntity.getOtherStructure()));
        }
        List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {

            @Override
            public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
                return (int) (o2.getValue() - o1.getValue());
            }
        });
        Map result = new LinkedHashMap();
        for (Map.Entry<String, Double> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }
        return result;
    }

    public void compareAndSwap(ResultMainEntityVO resultMainEntity, ResultMainEntityVO entity) throws IllegalAccessException {
        Field[] fields = resultMainEntity.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            String name = field.getName();
            CompareAndSwap compareAndSwap = field.getAnnotation(CompareAndSwap.class);
            field.setAccessible(true);
            if (compareAndSwap == null) {
                continue;
            }
            Object resultObj = getFieldValue(resultMainEntity, name);
            Object entityObj = getFieldValue(entity, name);
            if (resultObj == null) {
                field.set(resultMainEntity, entityObj == null ? "" : entityObj);
                continue;
            }
            if (entityObj == null) {
                continue;
            }
            String mainStr = resultObj.toString();
            String entityStr = entityObj.toString();
            field.set(resultMainEntity, getMaxMin(mainStr,entityStr));
        }
    }

    public void compareAndSwap(PrefectureResultEntity pvo, PrefectureResultEntity entity) throws IllegalAccessException {
        Field[] fields = pvo.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            String name = field.getName();
            CompareAndSwap compareAndSwap = field.getAnnotation(CompareAndSwap.class);
            field.setAccessible(true);
            if (compareAndSwap == null) {
                continue;
            }
            Object resultObj = getFieldValue(pvo, name);
            Object entityObj = getFieldValue(entity, name);
            if (resultObj == null) {
                field.set(pvo, entityObj == null ? "" : entityObj);
                continue;
            }
            if (entityObj == null) {
                field.set(pvo, resultObj);
                continue;
            }
            String mainStr = resultObj.toString();
            String entityStr = entityObj.toString();
            field.set(pvo, getMaxMin(mainStr,entityStr));
        }
    }
    /**
     * 反射时根据属性获取属性值
     */
    private Object getFieldValue(Object thisClass, String fieldName) {
        Object value = new Object();
        Method method = null;
        try {
            String methodName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
            method = thisClass.getClass().getMethod("get" + methodName);
            value = method.invoke(thisClass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }

    public  List<String> buildStrList(Object obj) {
        List<String> list = new ArrayList<>();
        PrefectureResultEntity prefectureResultEntity = null;
        ResultMainEntity resultEntity = null;
        ResultEntity result = null;
        ResultMainEntityVO vo = null;
        Field[] fields = null;
        if (obj instanceof PrefectureResultEntity) {
            prefectureResultEntity = (PrefectureResultEntity) obj;
            fields = prefectureResultEntity.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Transform transform = field.getAnnotation(Transform.class);
                field.setAccessible(true);
                if (transform == null) {
                    continue;
                }
                Object valueObj = getFieldValue(prefectureResultEntity, name);
                list.add(equals(valueObj) ? "" : valueObj.toString());
            }
        } else if (obj instanceof ResultMainEntity) {
            resultEntity = (ResultMainEntity) obj;
            fields = resultEntity.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Transform transform = field.getAnnotation(Transform.class);
                field.setAccessible(true);
                if (transform == null) {
                    continue;
                }
                Object valueObj = getFieldValue(resultEntity, name);
                if (valueObj != null) {
                    list.add(equals(valueObj) ? "" : valueObj.toString());
                }

            }
        } else if (obj instanceof ResultEntity) {
            result = (ResultEntity) obj;
            fields = result.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Transform transform = field.getAnnotation(Transform.class);
                field.setAccessible(true);
                if (transform == null ) {
                    continue;
                }
                Object valueObj = getFieldValue(result, name);
                if (valueObj != null) {
                    list.add(equals(valueObj) ? "" : valueObj.toString());
                }
            }
        } else if (obj instanceof ResultMainEntityVO) {
            vo = (ResultMainEntityVO) obj;
            fields = vo.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                Transform transform = field.getAnnotation(Transform.class);
                field.setAccessible(true);
                if (transform == null) {
                    continue;
                }
                Object valueObj = getFieldValue(vo, name);
                if (valueObj != null) {
                    list.add(equals(valueObj) ? "" : valueObj.toString());
                }
            }
        }
        return list;
    }

    public void addData(ResultMainEntityVO resultMainEntity, ResultMainEntityVO entity) throws IllegalAccessException {
        Field[] fields = resultMainEntity.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            String name = field.getName();
            AddData addData = field.getAnnotation(AddData.class);
            field.setAccessible(true);
            if (addData == null) {
                continue;
            }
            Object resultObj = getFieldValue(resultMainEntity, name);
            Object entityObj = getFieldValue(entity, name);
            if (resultObj == null) {
                field.set(resultMainEntity, entityObj == null ? "" : entityObj);
                continue;
            }
            if (entityObj == null) {
                field.set(resultMainEntity, resultObj);
                continue;
            }
            String mainStr = resultObj.toString();
            String entityStr = entityObj.toString();
            field.set(resultMainEntity, getMaxMin(mainStr,entityStr));
        }
    }

    private String getMaxMin(String mainStr,String entityStr){
        String minResult = mainStr.indexOf("-") > 0 ? mainStr.split("-")[0] : mainStr;
        String maxResult = mainStr.indexOf("-") > 0 ? mainStr.split("-")[1] : mainStr;

        String minEntity = entityStr.indexOf("-") > 0 ? entityStr.split("-")[0] : entityStr;
        String maxEntity = entityStr.indexOf("-") > 0 ? entityStr.split("-")[1] : entityStr;

        int minR = Integer.parseInt(minResult);
        int minE = Integer.parseInt(minEntity);
        Integer min = (minR==minE?minR:Integer.min(minR,minE));
        int maxR = Integer.parseInt(maxResult);
        int maxE = Integer.parseInt(maxEntity);
        Integer max = (maxR==maxE?maxR:Integer.max(maxR,maxE));
        if(min.equals(max)){
            return min+"";
        }
        return min+"-"+max;
    }

    /**
     * 简本版本1中大文本数据的构建
     */
    public String getZhqjfxText(Object obj) {
        StringBuilder zhqjfx = new StringBuilder("\r\n");
        List<Map<String, String>> list = (List<Map<String, String>>) obj;
        if (PlatformObjectUtils.isNotEmpty(list)) {
            int i = 0;
            for (Map<String, String> map : list) {
                String areaName = map.get("areaName");
                if (areaName.contains("北京市") || areaName.contains("天津市") || areaName.contains("上海市") || areaName.contains("重庆市")) {
                    //去重
                    areaName = removeRepeat(areaName);
                }
                zhqjfx.append(areaName).append("\r\n");
                zhqjfx.append("1.建筑物破坏").append("\r\n");
                zhqjfx.append("\t").append(map.get("buildingDamage") == null ? "" : map.get("buildingDamage")).append("\r\n");
                zhqjfx.append("2.人员伤亡").append("\r\n");
                zhqjfx.append("\t").append(map.get("casualties") == null ? "" : map.get("casualties")).append("\r\n");
                zhqjfx.append("3.地质灾害").append("\r\n");
                zhqjfx.append("\t").append(map.get("geologicHazard") == null ? "" : map.get("geologicHazard")).append("\r\n");
                zhqjfx.append("4.次生灾害").append("\r\n");
                zhqjfx.append("\t").append(map.get("secondaryDisaster") == null ? "" : map.get("secondaryDisaster")).append("\r\n");
                zhqjfx.append("5.震后交通").append("\r\n");
                zhqjfx.append("\t").append(map.get("earthquakeTraffic") == null ? "" : map.get("earthquakeTraffic")).append("\r\n");
                zhqjfx.append("6.其他灾害情景").append("\r\n");
                zhqjfx.append("\t").append(map.get("otherDisaster") == null ? "" : map.get("otherDisaster"));
                if (i != list.size() - 1) {
                    zhqjfx.append("\r\n").append("\r\n");
                }
                i++;
            }
        }
        return zhqjfx.toString();
    }

    /**
     * 去重
     */
    private String removeRepeat(String areaName) {
        //非空判断
        if (areaName == null) {
            return null;
        }
        StringBuilder sbd = new StringBuilder();//创建一个空的StringBuilder
        for (int i = 0; i < areaName.length(); i++) {
            char c = areaName.charAt(i);
            if (areaName.indexOf(c) == areaName.lastIndexOf(c)) {//第一次出现的下标跟最后一次相等,表示当前字符没有出现重复,直接添加进StringBuilder中
                sbd.append(c);
            } else {//出现重复
                if (areaName.indexOf(c) == i) {//如果重复出现的字符的位置等于当先字符的索引值,即表示当前字符为重复字符出现的第一次,将其加入StringBuilder中
                    sbd.append(c);
                }
            }
        }
        return sbd.toString();
    }
    /**
     * 简本版本1中大文本数据的构建
     */
    public String getYjzbczText(Object obj) {
        StringBuilder build = new StringBuilder("\r\n");
        List<Map<String, String>> list = (List<Map<String, String>>) obj;
        if (PlatformObjectUtils.isNotEmpty(list)) {
            int i = 0;
            for (Map<String, String> map : list) {
                String areaName = map.get("areaName");
                if (areaName.contains("北京市") || areaName.contains("天津市") || areaName.contains("上海市") || areaName.contains("重庆市")) {
                    //去重
                    areaName = removeRepeat(areaName);
                }
                build.append(areaName).append("\r\n");
                build.append("1.地震应急组织体系和预案体系").append("\r\n");
                build.append("\t").append(map.get("emergencySystem") == null ? "" : map.get("emergencySystem")).append("\r\n");
                build.append("2.地震应急工作机制").append("\r\n");
                build.append("\t").append(map.get("emergencyWorkingMechanism") == null ? "" : map.get("emergencyWorkingMechanism")).append("\r\n");
                build.append("3.应急物资储备").append("\r\n");
                build.append("\t").append(map.get("emergencySuppliesReserve") == null ? "" : map.get("emergencySuppliesReserve")).append("\r\n");
                build.append("4.应急救援力量").append("\r\n");
                build.append("\t").append(map.get("emergencyRescueForce") == null ? "" : map.get("emergencyRescueForce")).append("\r\n");
                build.append("5.应急避难场所").append("\r\n");
                build.append("\t").append(map.get("emergencyShelter") == null ? "" : map.get("emergencyShelter")).append("\r\n");
                build.append("6.重点目标保障能力").append("\r\n");
                build.append("\t").append(map.get("supportability") == null ? "" : map.get("supportability")).append("\r\n");
                build.append("7.谣言、舆情应急能力").append("\r\n");
                build.append("\t").append(map.get("rumorEmergencyCapacity") == null ? "" : map.get("rumorEmergencyCapacity")).append("\r\n");
                build.append("8.科普宣教和演练").append("\r\n");
                build.append("\t").append(map.get("popularization") == null ? "" : map.get("popularization")).append("\r\n");
                build.append("9.其他地方特征应急准备措施").append("\r\n");
                build.append("\t").append(map.get("otherMeasures") == null ? "" : map.get("otherMeasures"));
                if (i != list.size() - 1) {
                    build.append("\r\n").append("\r\n");
                }
                i++;
            }
        }
        return build.toString();
    }

    /**
     * 简本版本1中大文本数据的构建
     */
    public String getYjczdcText(Object obj) {
        StringBuilder build = new StringBuilder("\r\n");
        List<Map<String, String>> list = (List<Map<String, String>>) obj;
        if (PlatformObjectUtils.isNotEmpty(list)) {
            int i = 0;
            for (Map<String, String> map : list) {
                String areaName = map.get("areaName");
                if (areaName.contains("北京市") || areaName.contains("天津市") || areaName.contains("上海市") || areaName.contains("重庆市")) {
                    //去重
                    areaName = removeRepeat(areaName);
                }
                build.append(areaName).append("\r\n");
                build.append("1.救援力量和物资投入").append("\r\n");
                build.append("\t").append(map.get("rescueForceMaterialInput") == null ? "" : map.get("rescueForceMaterialInput")).append("\r\n");
                build.append("2.地震灾害危重区域识别").append("\r\n");
                build.append("\t").append(map.get("earthquakeDisasterCriticalArea") == null ? "" : map.get("earthquakeDisasterCriticalArea")).append("\r\n");
                build.append("3.交通系统保障和抢修").append("\r\n");
                build.append("\t").append(map.get("trafficSystemSupportRepair") == null ? "" : map.get("trafficSystemSupportRepair")).append("\r\n");
                build.append("4.通信系统保障和抢修").append("\r\n");
                build.append("\t").append(map.get("communicationsSystemSupportRepair") == null ? "" : map.get("communicationsSystemSupportRepair")).append("\r\n");
                build.append("5.电力系统保障和抢修").append("\r\n");
                build.append("\t").append(map.get("powerSystemSupportRepair") == null ? "" : map.get("powerSystemSupportRepair")).append("\r\n");
                build.append("6.重要基础设施隐患排查").append("\r\n");
                build.append("\t").append(map.get("importantFacilitiesCheck") == null ? "" : map.get("importantFacilitiesCheck")).append("\r\n");
                build.append("7.气候特征应对").append("\r\n");
                build.append("\t").append(map.get("climateFeatureReply") == null ? "" : map.get("climateFeatureReply")).append("\r\n");
                build.append("8.民族特征应对").append("\r\n");
                build.append("\t").append(map.get("nationFeatureReply") == null ? "" : map.get("nationFeatureReply")).append("\r\n");
                build.append("9.谣言、舆情应对").append("\r\n");
                build.append("\t").append(map.get("rumorReply") == null ? "" : map.get("rumorReply")).append("\r\n");
                build.append("10.其他地方特征应对").append("\r\n");
                build.append("\t").append(map.get("otherFeatureReply") == null ? "" : map.get("otherFeatureReply"));
                if (i != list.size() - 1) {
                    build.append("\r\n").append("\r\n");
                }
                i++;
            }
        }
        return build.toString();
    }

    /**
     * 数据单位转换：人转换为万人并保留4位小数
     */
    public void handleResult(PrefectureResultEntity pr,ResultMainEntityVO re) {
        //需要的帐篷数
        String tentNum = "";
        if(pr!=null){
            tentNum = pr.getTentNum();
            if (StringUtils.isBlank(tentNum)) {
                pr.setTentNum("");
            }
        }
        if(re!=null){
            tentNum = re.getTentNumAfter();
            if (StringUtils.isBlank(tentNum)) {
                re.setTentNumAfter("");
            }
        }
        if(StringUtils.isNotBlank(tentNum)){
            String[] split = tentNum.split("-");
            String tent = "";
            BigDecimal prefix = new BigDecimal(split[0]);
            if(split.length==2){
                BigDecimal subfix = new BigDecimal(split[1]);
                BigDecimal prefixDivide = prefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:prefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
                BigDecimal subfixDivide = subfix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
                tent = prefixDivide+"-"+subfixDivide;
            }else{
                BigDecimal prefixDivide = prefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:prefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
                tent = prefixDivide+"";
            }
            if(pr!=null){
                pr.setTentNum(tent);
            }
            if(re!=null){
                re.setTentNumAfter(tent);
            }
        }
        //处理紧急安置人数
        String resettledNum = "";
        if(pr!=null){
            resettledNum = pr.getResettledNum();
            if (StringUtils.isBlank(resettledNum)) {
                pr.setResettledNum("");
            }
        }
        if(re!=null){
            resettledNum = re.getResettledNumAfter();
            if (StringUtils.isBlank(resettledNum)) {
                re.setResettledNumAfter("");
            }
        }
        if(StringUtils.isNotBlank(resettledNum)){
            String[] resettSplit = resettledNum.split("-");
            String resettled = "";
            BigDecimal resettledPrefix = new BigDecimal(resettSplit[0]);
            if(resettSplit.length==2){
                BigDecimal resettledSubfix = new BigDecimal(resettSplit[1]);
                BigDecimal prefixMultiply = resettledPrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:resettledPrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
                BigDecimal subfixMultiply = resettledSubfix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
                resettled = prefixMultiply+"-"+subfixMultiply;
            }else{
                BigDecimal prefixMultiply = resettledPrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:resettledPrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
                resettled = prefixMultiply+"";
            }
            if(pr!=null){
                pr.setResettledNum(resettled);
            }
            if(re!=null){
                re.setResettledNumAfter(resettled);
            }
        }
        //死亡人数
//        String deathNum = "";
//        if(pr!=null){
//            deathNum = pr.getDeathToll();
//            if (StringUtils.isBlank(deathNum)) {
//                pr.setDeathToll("");
//            }
//        }
//        if(re!=null){
//            deathNum = re.getDeathTollAfter();
//            if (StringUtils.isBlank(deathNum)) {
//                re.setDeathTollAfter("");
//            }
//        }
//        if (StringUtils.isNotBlank(deathNum)) {
//            String[] deathNumSplit = deathNum.split("-");
//            String death = "";
//            BigDecimal deathPrefix = new BigDecimal(deathNumSplit[0]);
//            if(deathNumSplit.length==2){
//                BigDecimal deathSubfix = new BigDecimal(deathNumSplit[1]);
//                BigDecimal prefixMultiply = deathPrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:deathPrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                BigDecimal subfixMultiply = deathSubfix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                death = prefixMultiply+"-"+subfixMultiply;
//            }else{
//                BigDecimal prefixMultiply = deathPrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:deathPrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                death = prefixMultiply+"";
//            }
//            if(pr!=null){
//                pr.setDeathToll(death);
//            }
//            if(re!=null){
//                re.setDeathTollAfter(death);
//            }
//        }
//
//        //受伤人数
//        String injureNum = "";
//        if(pr!=null){
//            injureNum = pr.getInjuredNum();
//            if (StringUtils.isBlank(injureNum)) {
//                pr.setInjuredNum("");
//            }
//        }
//        if(re!=null){
//            injureNum = re.getInjuredNumAfter();
//            if (StringUtils.isBlank(injureNum)) {
//                re.setInjuredNumAfter("");
//            }
//        }
//        if (StringUtils.isNotBlank(injureNum)) {
//            String[] injureSplit = injureNum.split("-");
//            String injure = "";
//            BigDecimal injurePrefix = new BigDecimal(injureSplit[0]);
//            if(injureSplit.length==2){
//                BigDecimal injureSubfix = new BigDecimal(injureSplit[1]);
//                BigDecimal prefixMultiply = injurePrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:injurePrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                BigDecimal subfixMultiply = injureSubfix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                injure = prefixMultiply+"-"+subfixMultiply;
//            }else{
//                BigDecimal prefixMultiply = injurePrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:injurePrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                injure = prefixMultiply+"";
//            }
//            if(pr!=null){
//                pr.setInjuredNum(injure);
//            }
//            if(re!=null){
//                re.setInjuredNumAfter(injure);
//            }
//        }
//
//        //救援人数
//        String rescueNum = "";
//        if(pr!=null){
//            rescueNum = pr.getRescueForce();
//            if (StringUtils.isBlank(rescueNum)) {
//                pr.setRescueForce("");
//            }
//        }
//        if(re!=null){
//            rescueNum = re.getRescueForceAfter();
//            if (StringUtils.isBlank(rescueNum)) {
//                re.setRescueForceAfter("");
//            }
//        }
//        if (StringUtils.isNotBlank(rescueNum)) {
//            String[] rescueSplit = rescueNum.split("-");
//            String rescue = "";
//            BigDecimal rescuePrefix = new BigDecimal(rescueSplit[0]);
//            if(rescueSplit.length==2){
//                BigDecimal rescueSubfix = new BigDecimal(rescueSplit[1]);
//                BigDecimal prefixMultiply = rescuePrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:rescuePrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                BigDecimal subfixMultiply = rescueSubfix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                rescue = prefixMultiply+"-"+subfixMultiply;
//            }else{
//                BigDecimal prefixMultiply = rescuePrefix.compareTo(BigDecimal.ZERO)==0?BigDecimal.ZERO:rescuePrefix.divide(new BigDecimal(10000),4, RoundingMode.HALF_UP);
//                rescue = prefixMultiply+"";
//            }
//            if(pr!=null){
//                pr.setRescueForce(rescue);
//            }
//            if(re!=null){
//                re.setRescueForceAfter(rescue);
//            }
//        }

    }

    public StructureType getTownRatio(HosPeoEntity hosPeo) {
        if(hosPeo==null){
            return null;
        }
        StructureType structureType = StructureType.builder()
                .province(hosPeo.getProvince()).city(hosPeo.getCity()).prefecture(hosPeo.getPrefecture())
                .highRatio(hosPeo.getDhpTownHighTatio()+"").steelRatio(hosPeo.getDhpTownSteelTatio()+"")
                .mutilRatio(hosPeo.getDhpTownBetonTatio()+"").brickRatio(hosPeo.getDhpTownBrickTatio()+"")
                .birckWoodRatio(hosPeo.getDhpTownMasonryTatio()+"").soilRatio(hosPeo.getDhpTownSoilTatio()+"")
                .woodRatio(hosPeo.getDhpTownWoodTatio()+"").stoneRatio(hosPeo.getDhpTownStoneTatio()+"")
                .otherRatio(hosPeo.getDhpTownOtherTatio()+"").build();
        return structureType;
    }

    /**
     * 获取人口和建筑物概况中农村各建筑类别的占比
     */
    public StructureType getVillageRatio(HosPeoEntity hosPeo) {
        if(hosPeo==null){
            return null;
        }
        StructureType structureType = StructureType.builder()
                .province(hosPeo.getProvince()).city(hosPeo.getCity()).prefecture(hosPeo.getPrefecture())
                .highRatio(hosPeo.getDhpVillageHighTatio()+"").steelRatio(hosPeo.getDhpVillageSteelTatio()+"")
                .mutilRatio(hosPeo.getDhpVillageBetonTatio()+"").brickRatio(hosPeo.getDhpVillageBrickTatio()+"")
                .birckWoodRatio(hosPeo.getDhpVillageMasonryTatio()+"").soilRatio(hosPeo.getDhpVillageSoilTatio()+"")
                .woodRatio(hosPeo.getDhpVillageWoodTatio()+"").stoneRatio(hosPeo.getDhpVillageStoneTatio()+"")
                .otherRatio(hosPeo.getDhpVillageOtherTatio()+"").build();
        return structureType;
    }

    public List<String> buildStrListV2(Object obj) {
        List<String> list = new ArrayList<>();
        PrefectureResultEntity prefectureResultEntity = null;
        ResultMainEntity resultEntity = null;
        ResultEntity result = null;
        ResultMainEntityVO vo = null;
        Field[] fields = null;
        if (obj instanceof PrefectureResultEntity) {
            prefectureResultEntity = (PrefectureResultEntity) obj;
            fields = prefectureResultEntity.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                TransformV2 transformV2 = field.getAnnotation(TransformV2.class);
                field.setAccessible(true);
                if ( transformV2==null) {
                    continue;
                }
                Object valueObj = getFieldValue(prefectureResultEntity, name);
                list.add(equals(valueObj) ? "" : valueObj.toString());
            }
        } else if (obj instanceof ResultMainEntity) {
            resultEntity = (ResultMainEntity) obj;
            fields = resultEntity.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                TransformV2 transformV2 = field.getAnnotation(TransformV2.class);
                field.setAccessible(true);
                if ( transformV2==null) {
                    continue;
                }
                Object valueObj = getFieldValue(resultEntity, name);
                if (valueObj != null) {
                    list.add(equals(valueObj) ? "" : valueObj.toString());
                }

            }
        } else if (obj instanceof ResultEntity) {
            result = (ResultEntity) obj;
            fields = result.getClass().getDeclaredFields();
            assert fields != null;
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                TransformV2 transformV2 = field.getAnnotation(TransformV2.class);
                field.setAccessible(true);
                if (transformV2==null) {
                    continue;
                }
                Object valueObj = getFieldValue(result, name);
                if (valueObj != null) {
                    list.add(equals(valueObj) ? "" : valueObj.toString());
                }
            }
        } else if (obj instanceof ResultMainEntityVO) {
            vo = (ResultMainEntityVO) obj;
            fields = vo.getClass().getDeclaredFields();
            assert fields != null;
            String macroPositionStr = "";
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                String name = field.getName();
                TransformV2 transformV2 = field.getAnnotation(TransformV2.class);
                field.setAccessible(true);
                if (transformV2==null) {
                    continue;
                }
                Object valueObj = getFieldValue(vo, name);
                String value = (valueObj==null ? "" : valueObj.toString());
                if(name.equals("macroPosition") && !"".equals(value)){
                    macroPositionStr = value;
                    value = (value.split(",")[0]+","+value.split(",")[1]);
                }

                list.add(value);
            }
        }

        return list;
    }

    public List<Map<String, List<List<String>>>> getCityResultListV3(List<ResultMainEntityVO> cityResultEntityList, List<ResultMainEntityVO> resultEntityList, List<PrefectureResultEntity> prefectureResultEntityList) throws IllegalAccessException {
        List<Map<String, List<List<String>>>> resultList = new ArrayList<>();
        String temp = "";
        if (cityResultEntityList != null) {
            List<Map<String, Map<BigDecimal,ResultMainEntityVO>>> voList = new ArrayList<>();
            Map<String,List<String>> tempMap = new HashMap<>();
            for (ResultMainEntityVO mainEntity : cityResultEntityList) {
                String macroPosition = mainEntity.getMacroPosition();
                String[] split = macroPosition.split(",");
                if(split.length>=3){
                    if(!tempMap.containsKey(split[1])){
                        List<String> tempList = new ArrayList<>();
                        tempList.add(split[2]);
                        tempMap.put(split[1],tempList);
                    }else{
                        List<String> tempList = tempMap.get(split[1]);
                        if (!tempList.contains(split[2])) {
                            tempList.add(split[2]);
                            tempMap.put(split[1], tempList);
                        }
                    }
                }
            }
            Map<String, Map<BigDecimal,ResultMainEntityVO>> resultMap = new HashMap<>();
            List<ResultMainEntityVO> voes = new ArrayList<>();
            ResultMainEntityVO tempVO = null;
            for (ResultMainEntityVO entity : cityResultEntityList) {
                //宏观位置
                String macroPosition = entity.getMacroPosition();
                String city = macroPosition.split(",")[1];
                if(tempMap.containsKey(city)){
                    List<String> tempList = tempMap.get(city);
                    String str = String.join(",", tempList);
                    entity.setImportantArea(str);
                }
                //震级
                BigDecimal magnitude = entity.getMagnitude();
                if (resultMap.containsKey(city)) {
                    Map<BigDecimal,ResultMainEntityVO> voMap = resultMap.get(city);
                    ResultMainEntityVO vo = voMap.get(magnitude);
                    if(vo!=null){
                        // 以地市为单位分别获取相同震级下的最大值和最小值
                        /**
                         * 重庆市,重庆市 5.5 59009-61741 177027-185224
                         * 重庆市,重庆市 6.0 87695-94869 263086-284607
                         * 重庆市,重庆市 6.5 76419-78609 229258-235829
                         */
                        compareAndSwap(vo, entity);
                        voMap.put(magnitude,vo);
                        resultMap.put(city,voMap);
                    }else{
                        voMap.put(magnitude,entity);
                        resultMap.put(city,voMap );
                    }
                } else {
                    Map<BigDecimal,ResultMainEntityVO> voMap = new HashMap<>();
                    voMap.put(magnitude,entity);
                    resultMap.put(city,voMap );
                }
            }
            if (resultMap.values().size() > 0) {
                voList.add(resultMap);
            }

            if (PlatformObjectUtils.isNotEmpty(voList)) {
                for (Map<String, Map<BigDecimal,ResultMainEntityVO>> voMap : voList) {
                    voMap.forEach((k,v)->{
                        Map<String, List<List<String>>> map = new HashMap<>();
                        List<List<String>> tempList = new ArrayList<>();
                        Map<BigDecimal,ResultMainEntityVO> tmap = v;
                        Set<Map.Entry<BigDecimal, ResultMainEntityVO>> entries = v.entrySet();
                        Iterator<Map.Entry<BigDecimal, ResultMainEntityVO>> iterator = entries.iterator();
                        while(iterator.hasNext()){
                            ResultMainEntityVO value = iterator.next().getValue();
                            List<String> strList = buildStrListV2(value);
                            tempList.add(strList);
                        }
                        map.put(k, tempList);
                        resultList.add(map);
                    });
                }

            }
        }
        if (resultEntityList != null) {
            List<Map<String, Map<BigDecimal,ResultMainEntityVO>>> voList = new ArrayList<>();
            Map<String,List<String>> tempMap = new HashMap<>();
            for (ResultMainEntityVO mainEntity : resultEntityList) {
                String macroPosition = mainEntity.getMacroPosition();

                String[] split = macroPosition.split(",");
                //if(split.length>=2){
                if(!tempMap.containsKey(split[1]+","+split[2])){
                    List<String> tempList = new ArrayList<>();
                    tempList.add(split[1]+","+split[2]);
                    tempMap.put(split[1]+","+split[2],tempList);
                }else{
                    List<String> tempList = tempMap.get(split[1]+","+split[2]);
                    if (!tempList.contains(split[1]+","+split[2])) {
                        tempList.add(split[1]+","+split[2]);
                        tempMap.put(split[1]+","+split[2], tempList);
                    }
                }
                //}
            }
            Map<String, Map<BigDecimal,ResultMainEntityVO>> resultMap = new HashMap<>();
            for (ResultMainEntityVO mainEntity : resultEntityList) {
                //宏观位置
                String macroPosition = mainEntity.getMacroPosition();
                if(macroPosition.equals("浙江省,绍兴市,嵊州市")){
                    System.out.println("222222");
                }
                mainEntity.setMacroPosition(macroPosition.split(",")[1]+","+macroPosition.split(",")[2]);
                String city = macroPosition.split(",")[1];
                String country = macroPosition.split(",")[2];
                if(tempMap.containsKey(city+","+country)){
                    List<String> tempList = tempMap.get(city+","+country);
                    String str = String.join(",", tempList);
                    mainEntity.setImportantArea(str);
                }
                //震级
//                BigDecimal magnitude = mainEntity.getMagnitude();
//                if (resultMap.containsKey(country + "_" + magnitude)) {
//                    ResultMainEntityVO entity = resultMap.get(country + "_" + magnitude);
//                    //compareAndSwap(entity, mainEntity);
//                    addData(entity, mainEntity);
//                } else {
////                    if (resultMap.values().size() > 0) {
////                        voList.add(resultMap);
////                        //resultMap = new HashMap<>();
////                    }
//                    resultMap.put(country + "_" + magnitude, mainEntity);
//                }

                BigDecimal magnitude = mainEntity.getMagnitude();
                if (resultMap.containsKey(city+","+country)) {
                    Map<BigDecimal,ResultMainEntityVO> voMap = resultMap.get(city+","+country);
                    ResultMainEntityVO vo = voMap.get(magnitude);
                    if(vo!=null){
                        addData(vo, mainEntity);
                        if("0".equals(vo.getRescueForceAfter())){
                            vo.setRescueForceAfter("");
                        }
                        if("0".equals(vo.getTentNumAfter())){
                            vo.setTentNumAfter("");
                        }
                        voMap.put(magnitude,vo);
                        resultMap.put(city+","+country,voMap);
                    }else{
                        String resettledNumAfter = mainEntity.getResettledNumAfter();
                        if(!"".equals(resettledNumAfter) && resettledNumAfter!=null && !resettledNumAfter.equals("null")){
                            mainEntity.setResettledNumAfter(divideTenThousand(new BigDecimal(resettledNumAfter))+"");
                        }
                        String tentNumAfter = mainEntity.getTentNumAfter();
                        if(!"".equals(tentNumAfter) && tentNumAfter!=null && !tentNumAfter.equals("null")){
                            mainEntity.setTentNumAfter(divideTenThousand(new BigDecimal(tentNumAfter))+"");
                        }
                        voMap.put(magnitude,mainEntity);
                        resultMap.put(city+","+country,voMap );
                    }
                } else {
                    Map<BigDecimal,ResultMainEntityVO> voMap = new HashMap<>();
                    //紧急安置人数和需要的帐篷，不管是按照区县生成还是地市生成，单位都是万 ，在此处理解决的是只有一条数据，不会存在数据比对的情况
                    String resettledNumAfter = mainEntity.getResettledNumAfter();
                    if(!"".equals(resettledNumAfter) && resettledNumAfter!=null && !resettledNumAfter.equals("null")){
                        mainEntity.setResettledNumAfter(divideTenThousand(new BigDecimal(resettledNumAfter))+"");
                    }
                    String tentNumAfter = mainEntity.getTentNumAfter();
                    if(!"".equals(tentNumAfter) && tentNumAfter!=null && !tentNumAfter.equals("null")){
                        mainEntity.setTentNumAfter(divideTenThousand(new BigDecimal(tentNumAfter))+"");
                    }
                    voMap.put(magnitude,mainEntity);
                    resultMap.put(city+","+country,voMap );
                }
            }
            if (resultMap.values().size() > 0) {
                voList.add(resultMap);
                resultMap = new HashMap<>();
            }
            if (PlatformObjectUtils.isNotEmpty(voList)) {
                for (Map<String, Map<BigDecimal,ResultMainEntityVO>> voMap : voList) {
                    voMap.forEach((k,v)->{
                        Map<String, List<List<String>>> map = new HashMap<>();
                        List<List<String>> tempList = new ArrayList<>();
                        Map<BigDecimal,ResultMainEntityVO> tmap = v;
                        Set<Map.Entry<BigDecimal, ResultMainEntityVO>> entries = v.entrySet();
                        Iterator<Map.Entry<BigDecimal, ResultMainEntityVO>> iterator = entries.iterator();
                        while(iterator.hasNext()){
                            ResultMainEntityVO value = iterator.next().getValue();
                            List<String> strList = buildStrListV2(value);
                            tempList.add(strList);
                        }
                        map.put(k, tempList);
                        resultList.add(map);
                    });
                }
            }
        }
        if (prefectureResultEntityList != null) {
            List<List<String>> tempList = new ArrayList<>();
            Map<String, List<List<String>>> map = new HashMap<>();
            List<String> strList = new ArrayList<>();
            for (PrefectureResultEntity entity : prefectureResultEntityList) {
//                String city = entity.getCity();
//                if ("".equals(temp)) {
//                    temp = city;
//                }
//                if (!temp.equals(city)) {
//                    map.put(temp, tempList);
//                    tempList = new ArrayList<>();
//                    resultList.add(map);
//                    map = new HashMap<>();
//                    temp = city;
//                }
                strList = buildStrListV2(entity);
                tempList.add(strList);
            }
            map.put(temp, tempList);
            resultList.add(map);
        }
        return resultList;
    }

    private BigDecimal divideTenThousand(BigDecimal value ){
        return value.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_DOWN);
    }

    public void center(XWPFTableCell cell) {
        CTTc ctTc = cell.getCTTc();
        CTTcPr ctTcPr = ctTc.addNewTcPr();
        ctTcPr.addNewVAlign().setVal(STVerticalJc.CENTER);
        CTTcBorders border = ctTcPr.addNewTcBorders();
        border.addNewBottom().setVal(STBorder.SINGLE);
        border.addNewRight().setVal(STBorder.SINGLE);
        border.addNewLeft().setVal(STBorder.SINGLE);
        border.addNewTop().setVal(STBorder.SINGLE);
        ctTc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
    }

    public List<String> getEveryKey(String runText) {
        List<Integer> list = new ArrayList<>();
        List<String> keyList = new ArrayList<>();
        char[] chars = runText.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '{') {
                list.add(++i);
            }
            if (chars[i] == '}') {
                list.add(i);
            }
        }
        StringBuilder key = new StringBuilder("");
        for (int i = 0; i < list.size(); i++) {
            key.append(runText.substring(list.get(i), list.get(++i)));
            keyList.add(key.toString());
            key = new StringBuilder("");
        }

        return keyList;
    }

    public  int getPictureType(String picType) {
        int res = CustomXWPFDocument.PICTURE_TYPE_PICT;
        if (picType != null) {
            if ("png".equalsIgnoreCase(picType)) {
                res = CustomXWPFDocument.PICTURE_TYPE_PNG;
            } else if ("dib".equalsIgnoreCase(picType)) {
                res = CustomXWPFDocument.PICTURE_TYPE_DIB;
            } else if ("emf".equalsIgnoreCase(picType)) {
                res = CustomXWPFDocument.PICTURE_TYPE_EMF;
            } else if ("jpg".equalsIgnoreCase(picType) || "jpeg".equalsIgnoreCase(picType)) {
                res = CustomXWPFDocument.PICTURE_TYPE_JPEG;
            } else if ("wmf".equalsIgnoreCase(picType)) {
                res = CustomXWPFDocument.PICTURE_TYPE_WMF;
            }
        }
        return res;
    }

    public Matcher matcher(String str) {
        Pattern pattern = Pattern.compile("\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        return matcher;
    }

    public void setTableHeadFontSize(String s, XWPFTableCell cell) {
        //设置字体大小
        XWPFRun run = getRun(cell);
        run.setFontSize(17);
        run.setText(s);
    }
    private XWPFRun getRun(XWPFTableCell cell){
        //获取 CTP
        CTTc ctTc = cell.getCTTc();
        CTP ctP = (ctTc.sizeOfPArray() == 0) ?ctTc.addNewP() : ctTc.getPArray(0);
        XWPFParagraph par = cell.getParagraph(ctP);
        XWPFRun run = par.createRun();
        return run;
    }
    public void mergeProvinceCell(int fromIndex, int rowSize, XWPFTable table, int cellSize, int from) {
        for (int rowIndex = fromIndex; rowIndex <= rowSize; rowIndex++) {
            for(int zz=from;zz<cellSize;zz++){
                XWPFTableCell mergeCell1 = table.getRow(rowIndex).getCell(zz);
                if (mergeCell1 != null) {
                    if (rowIndex == fromIndex) {
                        mergeCell1.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
                    } else {
                        mergeCell1.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
                    }
                    center(mergeCell1);
                }
            }
        }
    }
    public void mergeCell(int tempIndex,int rowSize,XWPFTable table,int cellSize,int from){
        if(cellSize>0){
            for (int rowIndex = tempIndex; rowIndex < rowSize; rowIndex++) {
                for(int zz=from;zz<cellSize;zz++){
                    XWPFTableCell mergeCell1 = table.getRow(rowIndex).getCell(zz);
                    if (mergeCell1 != null) {
                        if (rowIndex == tempIndex) {
                            mergeCell1.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
                        } else {
                            mergeCell1.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
                        }
                        center(mergeCell1);
                    }
                }
            }
        }
    }

    private XWPFRun getLeftRun(XWPFTableCell cell){
        //获取 CTP
        CTTc ctTc = cell.getCTTc();
        CTP ctP = (ctTc.sizeOfPArray() == 0) ?ctTc.addNewP() : ctTc.getPArray(0);
        XWPFParagraph par = cell.getParagraph(ctP);
        par.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun run = par.createRun();
        return run;
    }
    public void setTableFontSize(String s, XWPFTableCell cell) {
        //设置字体大小
        if(s.contains("\r\n")){
            for(String text : s.split("\r\n")){
                XWPFRun run = getLeftRun(cell);
                run.setFontSize(13);
                run.setText(text);
                run.addBreak();
            }
        }else{
            XWPFRun run = getRun(cell);
            run.setFontSize(13);
            run.setText(s);
        }

    }

    //单元格写入图片
    public  void setCellImage(XWPFTableCell cell,String urls)  {
        if (StringUtils.isBlank(urls)) {
            return;
        }
        String [] urlArray = urls.split(",");
        //String ctxPath=ResourceUtil.getConfigByName("webUploadpath");
        List<XWPFParagraph> paragraphs = cell.getParagraphs();
        XWPFParagraph newPara = paragraphs.get(0);
        XWPFRun imageCellRunn = newPara.createRun();
        for(String url:urlArray){
            //String downLoadPath = ctxPath+File.separator + url;
            File image = new File(url);
            if(!image.exists()){
                continue;
            }
            int format;
            if (url.endsWith(".emf")) {
                format = XWPFDocument.PICTURE_TYPE_EMF;
            } else if (url.endsWith(".wmf")) {
                format = XWPFDocument.PICTURE_TYPE_WMF;
            } else if (url.endsWith(".pict")) {
                format = XWPFDocument.PICTURE_TYPE_PICT;
            } else if (url.endsWith(".jpeg") || url.endsWith(".jpg")) {
                format = XWPFDocument.PICTURE_TYPE_JPEG;
            } else if (url.endsWith(".png")) {
                format = XWPFDocument.PICTURE_TYPE_PNG;
            } else if (url.endsWith(".dib")) {
                format = XWPFDocument.PICTURE_TYPE_DIB;
            } else if (url.endsWith(".gif")) {
                format = XWPFDocument.PICTURE_TYPE_GIF;
            } else if (url.endsWith(".tiff")) {
                format = XWPFDocument.PICTURE_TYPE_TIFF;
            } else if (url.endsWith(".eps")) {
                format = XWPFDocument.PICTURE_TYPE_EPS;
            } else if (url.endsWith(".bmp")) {
                format = XWPFDocument.PICTURE_TYPE_BMP;
            } else if (url.endsWith(".wpg")) {
                format = XWPFDocument.PICTURE_TYPE_WPG;
            } else {
                continue;
            }
            try (FileInputStream is = new FileInputStream(url)) {
                imageCellRunn.addPicture(is, format, image.getName(), Units.toEMU(100), Units.toEMU(100)); // 200x200 pixels
            }catch (Exception e){
                e.printStackTrace();
            }
//            imageCellRunn.addBreak();
        }
    }
}
